package cn.engage.product.service.impl;

import cn.engage.basic.config.BussinessException;
import cn.engage.org.domain.Employee;
import cn.engage.org.mapper.EmployeeMapper;
import cn.engage.pet.dto.AcceptDto;
import cn.engage.product.domain.ProductComment;
import cn.engage.product.mapper.ProductCommentMapper;
import cn.engage.product.service.IProductCommentService;
import cn.engage.basic.service.impl.BaseServiceImpl;
import cn.engage.user.domain.User;
import cn.engage.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 产品评价 服务实现类
 * </p>
 *
 * @author engage
 * @since 2022-11-03
 */
@Service
public class ProductCommentServiceImpl extends BaseServiceImpl<ProductComment> implements IProductCommentService {
    @Autowired
    private UserService userService;
    @Autowired
    private ProductCommentMapper productCommentMapper;
    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public void order(Long id, ProductComment productComment) {
        productComment.setProductId(id);
        productCommentMapper.add(productComment);
    }
    // 生成订单
    @Override
    public void accept(AcceptDto acceptDto) {
        ProductComment productComment = productCommentMapper.findByIdOne(acceptDto.getMsgId());
        if (productComment == null){
            throw new BussinessException("该信息不存在");
        }
        productComment.setState(1);
        // 生成订单
        synchronized (productComment.getId()){
            Employee employee = employeeMapper.findByIdOne(acceptDto.getHandler());
            if (employee == null){
                throw new BussinessException("没有该员工!");
            }
            // 生成订单
        }
    }

    @Override
    public void reject(Long msgId) {
       productCommentMapper.delete(msgId);
    }


}
